package com.xc.quickstart.admin.controller;

import com.xc.quickstart.admin.query.LogoutQuery;
import com.xc.quickstart.admin.query.SSOQuery;
import com.xc.quickstart.common.annotation.PassToken;
import com.xc.quickstart.common.model.ApiResponse;
import com.xc.quickstart.manager.sso.SsoManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author : pdl
 * @date : 2021/3/23 10:22
 */
@RestController
@RequestMapping("/admin/home")
@Slf4j
public class HomeController {
    @Autowired
    private SsoManager ssoManager;

    @Value("${sso.admin_app_id}")
    private String apiAppId;
    /**
     * 用户信息
     *
     * @param request
     * @return
     */
    @GetMapping(path = "/get_info")
    public ApiResponse userInfo(HttpServletRequest request) {
        String token = request.getHeader("tctoken");
        return ssoManager.getSimpleUserInfo(new SSOQuery(token, apiAppId));
    }

    /**
     * 用户登出
     *
     * @param request
     * @return
     */
    @PassToken
    @GetMapping(path = "/logout")
    public ApiResponse logout(HttpServletRequest request) {
        String token = request.getHeader("tctoken");
        return ssoManager.logout(new LogoutQuery(token));
    }

    /**
     * 用户菜单
     *
     * @param request
     * @returnLogControllerAspect
     */

    @PassToken
    @GetMapping(path = "/userMenu")
    public ApiResponse userMenu(HttpServletRequest request) {
        String token = request.getHeader("tctoken");
        return ssoManager.getUserMenu(new SSOQuery(token, apiAppId));
    }

}
